window.VDM = {
	
	
	init:function(){
		
		if(cc.sys.platform === cc.sys.BYTEDANCE_GAME){
			
			
			tt.getGameRecorderManager().onStop((res) => {
				VDM.showToast("录屏结束",res.videoPath);
				
                if(_FIGHT){
				    _CHOICEMANAGER.showChoice(_FIGHT.node,'shareVideo',{path:res.videoPath});
                }else if(_MAP){
                    _CHOICEMANAGER.showChoice(_MAP.node,'shareVideo',{path:res.videoPath});
                }
				
			});
			
			tt.getGameRecorderManager().onStart((res) => {
				VDM.showToast("录屏开始");
			});
			
		}
		
	},
	
	//getGameRecorderManager
	startRecord:function(){
		
		
		if(cc.sys.platform === cc.sys.BYTEDANCE_GAME){
			
			console.log("录屏.....");
			
			
			tt.getSystemInfo({
			  success(res) {
				const screenWidth = res.screenWidth;
				const screenHeight = res.screenHeight;
				const recorder = tt.getGameRecorderManager();
				var maskInfo = recorder.getMark();
				var x = (screenWidth - maskInfo.markWidth) / 2;
				var y = (screenHeight - maskInfo.markHeight) / 2;

				
				//添加水印并且居中处理
				recorder.start({
				  duration: 20,
				  isMarkOpen: true,
				  locLeft: x,
				  locTop: y,
				});
			  },
			});
			
		}
		
		
	},
	
	
	showToast:function(message){
		
		
		tt.showToast({
		  title: message,
		  duration: 2000,
		  success(res) {
			console.log(`${res}`);
		  },
		  fail(res) {
			console.log(`showToast调用失败`);
		  },
		});
		
		
	},
	
	
	showVideo:function(vpath){
		
		let canvas = tt.createCanvas();
		let context = canvas.getContext("2d");
		// 调用tt.createVideo方法时，必须保证已经存在一个上屏canvas（onScreenCanvas）
		let video = tt.createVideo();
		// 当设置了的`src`属性之后就能监听视频可播放
		video.src = vpath;
		video.onCanplay((scale) => {
		  video.play();
		});
		
	},
	
	
	shareVideo:function(vpath){
		
		//console.log("分享....");
		
		if(cc.sys.platform === cc.sys.BYTEDANCE_GAME){
		
			tt.shareAppMessage({
			  title: "这款水浒题材rpg小游戏让我重温同年,喜欢吞食天地的玩家看过来",
			  channel: "video",
			  extra: {
				videoTopics: ["逆乱水浒之山贼王"], // 抖音或头条小视频话题列表
				videoPath: vpath,
				withVideoId: true,
			  },
			  success(res) {
				VDM.showToast("分享成功");
			  },
			  fail(e) {
				VDM.showToast("分享失败");
			  },
			});
		
		}
	}
	
	
	
}